package com.untrance.shop.web.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author eugene zadyra
 */
@Controller
public class CommonController {

	public static final ModelAndView forward404 = new ModelAndView("forward:/error.html?code="
			+ HttpServletResponse.SC_NOT_FOUND);
	public static final ModelAndView redirect500 = new ModelAndView("redirect:/error.html?code="
			+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
	public static final ModelAndView redirect403 = new ModelAndView("redirect:/error.html?code="
			+ HttpServletResponse.SC_FORBIDDEN);

	@RequestMapping("/error.html")
	public ModelAndView handleError(HttpServletResponse response,
			@RequestParam(value = "code", required = true) Integer code) {
		
		response.setStatus(code);
		return new ModelAndView(code.toString());
	}
	
	@RequestMapping("/login.html")
	public ModelAndView login(HttpServletResponse response,
			@RequestParam(value = "error", required = false) boolean error) {
		ModelAndView mav = new ModelAndView("login");
		mav.addObject("error", error);
		return mav;
	}
}
